<?php

namespace app\common\service\order\pipeline\coupon;

use app\model\CouponOrder;
use think\Exception;

/**
 *  验证 参数
 */
class RequestValidate
{
    public static function handle(CouponOrder $couponOrder, $next)
    {

        $params = $couponOrder->params;
        $serv_type = $params['serv_type'] ?? '';

        if ($serv_type != PRODUCT_COUPON_SERV) {
            return $next($couponOrder);
        }

        $msg = dmjValidate([
            'serv_type' => 'require|number',
            'account' => 'require',
            'product_channel_id' => 'require|number',
//            'mobile' => 'require|mobile',
        ], [], $params);

        if ($msg) {
            throw new Exception($msg);
        }

        $couponOrder->serv_type = $serv_type;

        $next($couponOrder);
    }

}